/**
 * Created by root on 17-4-10.
 */
var stream = require('stream');
var util = require('util');
function ReadStream() {
    stream.Readable.call(this)
}

util.inherits(ReadStream, stream.Readable);

ReadStream.prototype._read = function () {
    this.push('I ');
    this.push('Love ');
    this.push('Imooc\n ');
    this.push(null);
};

function WriteStream() {
    stream.Writable.call(this);
    this._cached = new Buffer('');
}

util.inherits(WriteStream, stream.Writable);

WriteStream.prototype._write = function (chunk, encode, cb) {
    console.log(chunk.toString());
    cb();
};

function TransfromStream() {
    stream.Transform.call(this);
}

util.inherits(TransfromStream, stream.Transform);

TransfromStream.prototype._transform = function (chunk, encode, cb) {
    this.push(chunk);
    cb();
}

TransfromStream.prototype._flush = function (cb) {
    this.push('Oh Yeah!');
    cb();
}

var rs = new ReadStream();
var ws = new WriteStream();
var ts = new TransfromStream();

rs.pipe(ts).pipe(ws);